{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "输入数据: 0x212BEC\n",
      "myCrc最终CRC值二进制: 10100101000011001101011011011101\n",
      "myCrc最终CRC值16进制: 0xA50CD6DD\n"
     ]
    }
   ],
   "source": [
    "import myCRC\n",
    "import random\n",
    "\n",
    "# 随机选择位宽\n",
    "bitwidth = random.randint(1, 64)\n",
    "max_value_for_bitwidth = (1 << bitwidth) - 1\n",
    "input_data = random.randint(0, max_value_for_bitwidth) # 随机输入\n",
    "# input_data = 0x12345678 # 输入数据\n",
    "\n",
    "print(f\"输入数据: 0x{input_data:X}\")\n",
    "mycrc_result = myCRC.CRC_32_MPEG_2.calc_crc(input_data)\n",
    "final_crc_hex = hex(int(mycrc_result, 2))[2:].upper()\n",
    "print(f\"myCrc最终CRC值二进制: {mycrc_result}\")\n",
    "print(f\"myCrc最终CRC值16进制: 0x{final_crc_hex}\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
